<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/vue.js"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <script src="../Public/js/axios.js"></script>
    <script src="../Public/js/jquery.js"></script>
    <link rel="stylesheet" href="../Public/css/index-1.css">
    <link rel="stylesheet" href="../Public/css/site.css">
    <link rel="stylesheet" href="../Public/css/index1.css">
    <link rel="stylesheet" href="../Public/css/doc.css">
    <script src="js/api.js"></script>
</head>
<body >
<div id="app">
    <div>
        <label>名称：</label>
        <el-select v-model="value" placeholder="请选择"  @change="item($event)">
            <el-option
                    v-for="item in options"
                    :key="item.value"
                    :label="item.label"
                    :value="item.value">
            </el-option>
        </el-select>
    </div>
    <!--后台获取的内容-->
    <div class="cont">
        <label>内容：</label>
        <div id="body" class="width">
        </div>
    </div>
    <!--留言-->
    <div class="leaveBox">
        <label>留言：</label>
        <el-input type="textarea"  :rows="2" v-model="input" placeholder="请输入留言" class="width"></el-input><br>
    </div>
    <div class="btnBox width">
        <el-button @click="Next">下一步</el-button>
    </div>
</div>
</body>
<script>
    new Vue({
        el: '#app',
        data: {
            input: '',
            value: '',
            options: [],
            id: ''
        },
        created() {
            var list = localStorage.getItem("id")
            if (list) {
                this.value = localStorage.getItem("name")
                this.item(list)
            }
            this.list()
        },
        methods: {
            //   下一步
            Next() {
                var leipiNewField =  $("input[name=leipiNewField]").val()
                var html =  document.getElementById('body').innerHTML
                if (localStorage.getItem("uid")) {
                   var uid = localStorage.getItem("uid")
                }
                axios({
                    method: "post",
                    url: Api + 'sp/start',
                    params: {
                        fid: this.id,
                        fname: this.value,
                        html: html,
                        uid: uid,
                        msg: this.input
                    }
                }).then(res=>{
                    if (res.status == '200') {
                        this.$message({
                            type: 'success',
                            message: res.data.data
                        })
                        setTimeout(function () {
                            location.href = './list.html'
                        },2000)
                    } else {
                        this.$message({
                            type: 'error',
                            message: res.data.data
                        })
                    }
                })
            },
            // 留言
            leave() {
                axios({
                    method: "post",
                    url: Api + 'sp/goNextNode',
                    params: {
                        sid: this.id,
                        msg: this.input
                    }
                }).then(res=>{
                    console.log(res,'留言');
                })
            },
            list(){
                axios({
                    method: 'post',
                    url: Api + 'sp/findAllflow',
                }).then(res=>{
                    var name = res.data.flows
                    var arr = []
                    for(const item  in name){
                        const obj = {
                            value: name[item].id,
                            label: name[item].name
                        }
                        arr.push(obj)
                    }
                    this.options = arr
                })
            },
            item(a) {
                axios({
                    method: 'post',
                    url: Api + 'sp/getForm',
                    params:{
                        id: a
                    }
                }).then(res=>{
                    this.id = res.data.data.id
                    var  html = res.data.data.html
                    $("#body").html(html)
                })
            }

        }
    })
</script>
</html>